package com.cob.main;

import com.dalonedrau.engine.Engine;
import com.dalonedrau.engine.GameState;
import com.dalonedrau.opengl.FontProperties;
import com.dalonedrau.opengl.GameApplet;

/**
 * Applet entry point.
 * @author Donald
 */
public final class COBApplet extends GameApplet {
	private static COBApplet	instance;
	/** serial id. */
	private static final long	serialVersionUID	= 1L;
	/**
	 * @return the instance
	 */
	public static COBApplet getInstance() {
		return COBApplet.instance;
	}
	/** <code>LogItem</code> object. */
	// private static final Log LOGGER = LogFactory.getLog(AresApplet.class);
	public void exit() {
		COBApplet.instance.stop();
	}
	/*
	 * (non-Javadoc)
	 * @see java.applet.Applet#init()
	 */
	@Override
	public void init() {
		try {
			COBApplet.instance = this;
			FontProperties.getInstance().initFontProperties(
					"lovecraft_24.properties");
			new COBConstants();
			Init.initGameData();
			// System.setProperty("sun.java2d.noddraw", "true");
			// System.setProperty("sun.awt.noerasebackground", "true");
			// ADD SPLASH PAGE
			/*
			 * FontFactory.loadTrueTypeFont(
			 * Controller.getInstance().getGlobalString("FONT_DEFAULT"));
			 */
			// FontFactory.loadTrueTypeFont(Globals.FONT_DEFAULT);
			// Init.initGameData();
			// InitUI.init("ui.properties");
			// Controller.ANIMATOR.start();
			// Controller.switchScreen();
			// 60 frames per second
			final long fps = 60L;
			// engine should loop at 1 second / # of frames
			// so for 60 fps, the loop should take 16ms
			new Engine(1000L / fps);
			// Controller.getInstance().switchScreen();
			COBController.getInstance();
		} catch (Exception ex) {
			JOGLErrorHandler.getInstance().fatalError(ex);
		}
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void start() {
		// starts the actual applet
		try {
			GameState.getInstance().nextState();
		} catch (Exception ex) {
			COBApplet.getInstance().fatalError(ex);
		}
	}
}
